package com.itheima.tlais_web_management.controller;




import com.itheima.tlais_web_management.pojo.Book;
import com.itheima.tlais_web_management.pojo.Result;
import com.itheima.tlais_web_management.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping
    public Result list(){

        List<Book> list = bookService.list();

        return Result.success(list);
    }


//    @DeleteMapping("/books/{id}")
//    public Result deletebook(@PathVariable Integer id){
//        bookService.deletebook(id);
//        return Result.success();
//    }


    @DeleteMapping("/{id}")
    public Result deletebook(@PathVariable("id") Integer id) {
        bookService.delete(id);
        return Result.success();
    }

    @PutMapping
    public Result insert(@RequestBody Book book){
        bookService.insert(book);

        return Result.success();
    }

}
